<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="__STATIC__/plugin/layui/css/layui.css" rel="stylesheet" />
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<blockquote class="layui-elem-quote layui-text">
    发表文章
</blockquote>

<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-upload">
            <label class="layui-form-label">上传封面</label>
            <div class="layui-input-block" style="position: relative;">
                <div style="position: absolute;top:45%;left:5%;"><input type="file" name="file" class="layui-upload-file" id="upload" ></div>

                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="uploadImg" src="__IMG__/Logo_40.png" style="width:250px;height:250px;border-radius: 50%;">
                    <input type="hidden" name="cover" id="cover">
                </div>
            </div>

        </div>
    </div>
    <div class="layui-form-item">
    <label class="layui-form-label">金额</label>
    <div class="layui-input-block">
    <input type="text" name="price" lay-verify="title" autocomplete="off" placeholder="请输入金额" class="layui-input">
    </div>
    </div>
    <div class="layui-form-item">
    <label class="layui-form-label">支付显示内容</label>
    <div class="layui-input-block">
        <textarea name="content" id="pay_content" cols="30" rows="10" style="display: none"></textarea>
        <script id="container1" name="pay_content" type="text/plain">
    </script>
    </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">正文</label>
        <div class="layui-input-block">
            <textarea name="content" id="content" cols="30" rows="10" style="display: none"></textarea>
            <script id="container2" name="content" type="text/plain">
            </script>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
        </div>
    </div>
</form>
<!-- 配置文件 -->
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue1 = UE.getEditor('container1',{
        initialFrameWidth : "80%",
        initialFrameHeight :"500"
    });
    var ue2 = UE.getEditor('container2',{
        initialFrameWidth : "80%",
        initialFrameHeight :"500"
    });
</script>
<script src="https://cdn.bootcss.com/jquery/2.1.3/jquery.min.js"></script>
<script src="__STATIC__/plugin/layui/layui.js"></script>
<script src="__JS__/common.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.define(['form', 'layedit','upload'], function (exports) {

        var form = layui.form()
            , layedit = layui.layedit
            ,upload = layui.upload;

        layui.upload({
            url: baseUrl+"api/v1/upload" //上传接口
            ,success: function(res){ //上传成功后的回调
                $("#uploadImg").attr('src',res.data.url);
                $("#cover").val(res.data.img_id);
            }
        });

        form.on('submit(add)', function(data){
            // $("#pay_content").val(ue1.getContent());
            // $("#content").val(ue2.getContent());
            var index = layer.load(1);
            var data = $('form').serialize();
            urlAjax(baseUrl+'api/v1/pay',data,function(data){
                layer.close(index);
                if(data.status){
                    layer.msg(data.info, { icon: 5 });
                }else{
                    layer.msg(data.info, { icon: 6 });
                    layer.closeAll('page');
                    setTimeout(function(){
                        location.href = data.url;
                    },1500);
                }
            }, function(){
                layer.close(index);
                layer.msg('网络错误，请重试', { icon: 5 });
            },'POST');

            return false;
        });
    });

</script>

</body>
</html>